import os
import argparse
import collections

parser = argparse.ArgumentParser()
parser.add_argument("-p", "--pattern", default="'^ *.+\(\".*\"\)'", type=str, help="pattern to match content")
parser.add_argument("-i", "--include", default="BUILD.gn", type=str, help="files to be searched")
parser.add_argument("-b", "--black_dirs", default=(".repo", "."))
args = parser.parse_args()
pattern = args.pattern
include = args.include


def post_process(type: str):
    return type.split("(")[0].split(":")[2].strip()


content = os.popen("grep -Ern {p} --include={i}".format(p=pattern, i=include))
type_dict = dict()
for ttype in content:
    ttype = post_process(ttype)
    if ttype not in type_dict.keys():
        type_dict[ttype] = 0
    type_dict[ttype] = type_dict.get(ttype) + 1
type_tuple = collections.Counter(type_dict).most_common()
for t in type_tuple:
    print(t)
print(len(type_dict))
